<%@LANGUAGE="VBSCRIPT"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="ErrorHandler.asp" -->

<% on error resume next %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Help Email</title>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />

<script type="text/vbscript">
function send()
set t=document.getElementById("To")
set f=document.getElementById("From")
set s=document.getElementById("Subject")
set m=document.getElementById("Message")

set ef=document.getElementById("EmailForm")
missing=0

if t.selectedIndex=-1 then
	missingstr=missingstr & " - To" & vbcrlf
	missing=1
end if

if f.value="" then
	missingstr=missingstr & " - From" & vbcrlf
	missing=1
end if


if s.value="" then
	missingstr=missingstr & " - Subject" & vbcrlf
	missing=1
end if

if m.value="" then 
	missingstr=missingstr & " - Message" & vbcrlf
	missing=1
end if



if missing=1 then
	msgbox "Cant Send Email. The Following Fields Where Left Blank:" & vbcrlf & missingstr
else
	ef.action="HelpEmail.asp?action=save"
	ef.Submit()
end if
end function
</script>
</head>

<body>
<table width="100%" height="40" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td background="Images/HeaderBG2.png"><img src="Images/LeftArrow.gif" alt="Back" name="BtnBack" width="35" height="35" id="BtnBack" onclick="javascript:history.go(-1)"/> 
	<img src="Images/RightArrow.gif" alt="Forward" name="BtnForward" width="35" height="35" border="0" id="BtnForward" onclick="javascript:history.go(1)"/></td>
  </tr>
</table>
<p>
  <%
if request.QueryString("action")="save" then
		'send mail configuration
		
		if application("EmailServer")="" then server.Execute("GetEmailServer.asp")	
		if application("EmailServer")="" then 
			%><script type="text/vbscript">msgbox"No Email Server Set. Please Advise Your Administrator."</script><%
			response.End()
		end if
		
	sch = "http://schemas.microsoft.com/cdo/configuration/" 
    
    Set cdoConfig = CreateObject("CDO.Configuration") 
    
    With cdoConfig.Fields 
		.Item(sch & "sendusing") = 2 ' cdoSendUsingPort 
    	.Item(sch & "smtpserver") = application("EmailServer")
    	.update 
    End With 
	
	 Set cdoMessage = CreateObject("CDO.Message") 

	set email=server.CreateObject("cdo.message")
	with email
		Set .Configuration = cdoConfig
		.subject=request.Form("Subject")
		.from=request.Form("From")
		message="From:	" & request.Form("From") & vbcrlf & "Time:	" & now() & vbcrlf & request.Form("Message")
		.textbody=message
		mTo=request.Form("To")
		select case mTo
			case "support"
				set fs=server.CreateObject("scripting.filesystemobject")
				set ef=fs.opentextfile(server.MapPath("access/backend/SupportEmail.txt"),1,true)
				e=ef.readline
				sendTo=e
				ef.close
				set fs=nothing
			case "training"
				set fs=server.CreateObject("scripting.filesystemobject")
				set ef=fs.opentextfile(server.MapPath("access/backend/TrainingEmail.txt"),1,true)
				e=ef.readline
				sendTo=e
				ef.close
				set fs=nothing
		end select
		.to=sendTo
		
		.Send
		if err.number<>0 then ErrorHandler
	end with
	%>
</p>
<table width="340" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20" height="20" background="Images/TableUpperLeft.png"></td>
    <td height="20" background="Images/TableUpperMiddle.png"></td>
    <td width="20" height="20" background="Images/TableUpperRight.png"></td>
  </tr>
  <tr>
    <td width="20" background="Images/TableMiddleLeft.png"></td>
    <td bgcolor="#FFFFFF" class="ResultsAddress">Thank You. Your Message Has Been Sent.</td>
    <td width="20" background="Images/TableMiddleRight.png"></td>
  </tr>
  <tr>
    <td width="20" height="20" background="Images/TableLowerLeft.png"></td>
    <td height="20" background="Images/TableLowerMiddle.png"></td>
    <td width="20" height="20" background="Images/TableLowerRight.png"></td>
  </tr>
</table>
	<%
	response.End()
end if
%>

<form id="EmailForm" name="EmailForm" method="post" action="">
<table width="640" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20" height="20" background="Images/TableUpperLeft.png"></td>
    <td width="600" height="20" background="Images/TableUpperMiddle.png"></td>
    <td width="20" height="20" background="Images/TableUpperRight.png"></td>
  </tr>
  <tr>
    <td width="20" background="Images/TableMiddleLeft.png"></td>
    <td><table width="600" border="0" cellpadding="0" cellspacing="1" bgcolor="#006600">
      <tr>
        <td width="103" bgcolor="#FFFFFF" class="ResultsAddress">TO:</td>
        <td width="394" align="left" bgcolor="#FFFFFF" class="ResultsAddress"><p>
          <select name="To" size="2" id="To">
            <option value="training">Training</option>
            <option value="support">Software Support</option>
          </select>
            </p>
          <p></p></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF" class="ResultsAddress">FROM:</td>
        <td align="left" bgcolor="#FFFFFF" class="ResultsAddress"><p>
          <input name="From" type="text" id="From" size="60" />
            </p>
          <p></p></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF" class="ResultsAddress">SUBJECT:</td>
        <td align="left" bgcolor="#FFFFFF" class="ResultsAddress"><p>
          <input name="Subject" type="text" id="Subject" size="60" />
            </p>
          <p></p></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF" class="ResultsAddress">MESSAGE:</td>
        <td align="left" bgcolor="#FFFFFF" class="ResultsAddress"><p>
          <textarea name="Message" cols="60" rows="5" id="Message"></textarea>
            </p>
          <p></p></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF" class="ResultsAddress"></td>
        <td align="right" bgcolor="#FFFFFF" class="ResultsAddress"><img src="Images/SendButton.png" alt="Send" width="60" height="30" onclick="vbscript: send()"/></td>
      </tr>
    </table></td>
    <td width="20" background="Images/TableMiddleRight.png"></td>
  </tr>
  <tr>
    <td width="20" height="20" background="Images/TableLowerLeft.png"></td>
    <td width="600" height="20" background="Images/TableLowerMiddle.png"></td>
    <td width="20" height="20" background="Images/TableLowerRight.png"></td>
  </tr>
</table>

</form>
</body>
</html>
